package com.baselibrary.libs.Utils.netUtils.NoHttp.queue;

import com.alibaba.fastjson.JSONObject;

import java.util.Hashtable;
import java.util.Observable;

/**
 * Created by Administrator 于萌萌
 * 创建日期: 16:19 . 2017年03月01日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public abstract class BaseRequest<T> extends Observable {
    private int SUCCEED = 0xff1;
    private int UPDATA = 0xff2;
    private int FAILURE = 0xff3;
    private int START = 0xff4;
    private String tag;

    private String url;

    private Hashtable<String,String> mHashtable;

   // private Context mContext;

//    public Context getContext() {
//        return mContext;
//    }

    T clazz;

    public T getClazz() {
        return clazz;
    }

    public BaseRequest setClazz(T clazz) {
        this.clazz = clazz;
        return this;
    }

//    public BaseRequest setContext(Context context) {
//        mContext = context;
//        return this;
//    }

    public String getTag() {
        return tag;
    }

    public BaseRequest setTag(String tag) {
        this.tag = tag;
        return this;
    }

    public String getUrl() {
        return url;
    }

    public BaseRequest setUrl(String url) {
        this.url = url;
        return this;
    }

    public Hashtable<String, String> getHashtable() {
        return mHashtable;
    }

    public BaseRequest setHashtable(Hashtable<String, String> hashtable) {
        mHashtable = hashtable;
        return this;
    }




    //正常消息
    public JSONObject mJsonObject;
    public void setResult(JSONObject mJsonObject) {
        this.mJsonObject = mJsonObject;
        setChanged();
        notifyObservers(SUCCEED);
    }




    public Request_netWork_error getError() {
        return mError;
    }

    public int getUpData() {
        return upData;
    }

    public JSONObject getJsonObject() {
        return mJsonObject;
    }


    public BaseRequest(String tag, String url, Hashtable<String, String> hashtable) {
        this.tag = tag;
        this.url = url;
        mHashtable = hashtable;
    }

    //错误信息
    public Request_netWork_error mError;
    public void setParam_error(Request_netWork_error mError){
        this.mError = mError;
        setChanged();
        notifyObservers(FAILURE);
    }
    //进度
    public int upData;
    public void setUpData(int upData){
        this.upData = upData;
        setChanged();
        notifyObservers(UPDATA);
    }
    public void setStart(JSONObject mJsonObject){
        this.mJsonObject = mJsonObject;
        setChanged();
        notifyObservers(START);
    }


    @Override
    public String toString() {
        return "BaseRequest{" +
                "SUCCEED=" + SUCCEED +
                ", UPDATA=" + UPDATA +
                ", FAILURE=" + FAILURE +
                ", START=" + START +
                ", tag='" + tag + '\'' +
                ", url='" + url + '\'' +
                ", mHashtable=" + mHashtable +
                ", clazz=" + clazz +
                ", mJsonObject=" + mJsonObject +
                ", mError=" + mError +
                ", upData=" + upData +
                '}';
    }
}
